<template>
  <div class="box2">
    <div class="title">
      <p>年龄比例</p>
      <img src="../../images/dataScreen-title.png" alt="" />
    </div>
    <!-- 饼图 -->
    <div class="charts" ref="chartsRef"></div>
  </div>
</template>

<script setup lang="ts">
import * as echarts from "echarts";
import { onMounted, ref } from "vue";
const chartsRef = ref<HTMLDivElement>();

onMounted(() => {
  const myChart = echarts.init(chartsRef.value);
  myChart.setOption({
    tooltip: {
      trigger: "item",
    },
    legend: {
      top: "center",
      right: 50,
      orient: "vertical", // 图例组件方向设置
      textStyle: {
        color: "white", // 图例组件文字颜色
        fontSize: 14,
      },
    },
    series: [
      {
        name: "年龄比例",
        type: "pie",
        radius: ["40%", "70%"],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 10,
          borderColor: "#fff",
          borderWidth: 2,
        },
        label: {
          show: false,
          position: "inside",
          color: "white",
        },
        labelLine: {
          show: false,
        },
        data: [
          { value: 1048, name: "15-18" },
          { value: 735, name: "18-30" },
          { value: 580, name: "30-40" },
          { value: 484, name: "40-60" },
          { value: 300, name: "60+" },
        ],
        center: ["40%", "49%"], // 饼图的位置
      },
    ],
    grid: {
      left: 0,
      right: 0,
      bottom: 0,
      top: 0,
    },
  });
});
</script>

<style scoped lang="scss">
.box2 {
  margin-top: 10px;
  width: 100%;
  height: 100%;
  background: url(../../images/dataScreen-main-cb.png) no-repeat;
  background-size: 100% 100%;

  .title {
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    margin-left: 20px;

    p {
      font-size: 22px;
      font-weight: bold;
      color: #ffffff;
    }

    img {
      width: 80px;
      height: auto;
    }
  }

  .charts {
    height: 260px;
  }
}
</style>
